/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import beans.Convite;
import beans.Usuario;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author alexandre
 */
public class DAOConvite {
    
    private EntityManager em;

    public DAOConvite(EntityManager em) {
        this.em = em;
    }

    public EntityManager getEm() {
        return em;
    }

    public void setEm(EntityManager em) {
        this.em = em;
    }
    
    public List<Convite> buscaConvites(Usuario u){
        
        Query q = em.createQuery("SELECT c FROM Convite c WHERE c.userReceiver.id = " + u.getId());
        
        return q.getResultList();
    }
    
//    public boolean solitacaoPendente(Long us, Long amigo){
//        Query query = em.createQuery("SELECT c FROM Convite c WHERE c.userReceiver.id = " + amigo.toString() + " AND c.userSender.id = " + us.toString());
//        System.out.println("SQL CONVITE ----------------------------------" + query);
//        Convite c = new Convite();
//        try {
//            c = (Convite) query.getSingleResult();
//        } catch (Exception e) {
//            c = null;
//        }
//        if(c == null){
//            return false;
//        }else{
//            return true;
//        }
//    }
    
}
